package com.ruoyi.module.szAccountRecord.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.szAccountRecord.domain.SzAccountRecord;
import com.ruoyi.module.szAccountRecord.domain.SzAccountRecordVO;
import com.ruoyi.module.szAccountRecord.service.ISzAccountRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 账号记录Controller
 * 
 * @author ${author}
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/protal/module/szAccount")
public class SzAccountRecordController extends BaseController
{
    @Autowired
    private ISzAccountRecordService szAccountRecordService;

    /**
     * 查询账号记录列表
     */
    // @PreAuthorize("@ss.hasPermi('module:record:list')")
    @GetMapping("/list")
    public AjaxResult list(SzAccountRecord szAccountRecord)
    {
        return szAccountRecordService.selectSzAccountRecordList(szAccountRecord);
    }


    /**
     * 获取账号记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(szAccountRecordService.selectSzAccountRecordById(id));
    }

    /**
     * 新增账号记录
     */
    // @PreAuthorize("@ss.hasPermi('module:record:add')")
    @Log(title = "账号记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzAccountRecordVO szAccountRecord)
    {
        try {
            szAccountRecordService.insertSzAccountRecord(szAccountRecord);
            return AjaxResult.success();
        } catch (Exception e) {
            logger.error("新增账号记录失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改账号记录
     */
    @PreAuthorize("@ss.hasPermi('module:record:edit')")
    @Log(title = "账号记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzAccountRecord szAccountRecord)
    {
        return toAjax(szAccountRecordService.updateSzAccountRecord(szAccountRecord));
    }

    /**
     * 删除账号记录
     */
    @Log(title = "账号记录", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szAccountRecordService.deleteSzAccountRecordByIds(ids));
    }
}
